﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.GameMenus;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000315 RID: 789
	public class LordWantsRivalCapturedIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D83 RID: 11651 RVA: 0x000BE7A8 File Offset: 0x000BC9A8
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D84 RID: 11652 RVA: 0x000BE7C1 File Offset: 0x000BC9C1
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x06002D85 RID: 11653 RVA: 0x000BE7C4 File Offset: 0x000BC9C4
		private bool ConditionsHold(Hero issueGiver, out Hero targetHero)
		{
			targetHero = null;
			if (issueGiver.IsLord && !issueGiver.IsMinorFactionHero && issueGiver.Clan.Leader == issueGiver && issueGiver.Clan != Clan.PlayerClan && issueGiver.GetTraitLevel(DefaultTraits.Mercy) <= 0 && issueGiver.GetTraitLevel(DefaultTraits.Honor) <= 0 && issueGiver.GetTraitLevel(DefaultTraits.Valor) <= 0)
			{
				List<Clan> list = Clan.FindAll((Clan x) => x.MapFaction != issueGiver.MapFaction && x.MapFaction.IsAtWarWith(issueGiver.MapFaction) && x.Lords.Count > 0).ToList<Clan>();
				int count = list.Count;
				if (count > 0)
				{
					int num = MBRandom.RandomInt(count);
					int num2 = num;
					bool flag = true;
					Func<Hero, bool> <>9__1;
					do
					{
						Clan clan = list[num2];
						MBReadOnlyList<Hero> lords = clan.Lords;
						Func<Hero, bool> predicate;
						if ((predicate = <>9__1) == null)
						{
							predicate = (<>9__1 = ((Hero noble) => noble.IsAlive && !noble.IsKingdomLeader && noble.PartyBelongedTo != null && noble.PartyBelongedTo.MemberRoster.TotalHealthyCount >= 50 && (float)noble.GetRelation(issueGiver) <= -10f));
						}
						targetHero = lords.GetRandomElementWithPredicate(predicate);
						num2++;
						if (num2 == count)
						{
							num2 = 0;
						}
						if (num2 == num)
						{
							flag = false;
						}
					}
					while (targetHero == null && flag);
				}
			}
			return targetHero != null;
		}

		// Token: 0x06002D86 RID: 11654 RVA: 0x000BE900 File Offset: 0x000BCB00
		public void OnCheckForIssue(Hero hero)
		{
			Hero relatedObject;
			if (this.ConditionsHold(hero, out relatedObject))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnSelected), typeof(LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue), IssueBase.IssueFrequency.Rare, relatedObject));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue), IssueBase.IssueFrequency.Rare));
		}

		// Token: 0x06002D87 RID: 11655 RVA: 0x000BE968 File Offset: 0x000BCB68
		private IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			PotentialIssueData potentialIssueData = pid;
			return new LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue(issueOwner, potentialIssueData.RelatedObject as Hero);
		}

		// Token: 0x04000D9F RID: 3487
		private const IssueBase.IssueFrequency LordWantsRivalCapturedIssueFrequency = IssueBase.IssueFrequency.Rare;

		// Token: 0x04000DA0 RID: 3488
		private const float TargetHeroRelationMaxRelation = -10f;

		// Token: 0x02000653 RID: 1619
		public class LordWantsRivalCapturedIssue : IssueBase
		{
			// Token: 0x060050F4 RID: 20724 RVA: 0x00170D1D File Offset: 0x0016EF1D
			internal static void AutoGeneratedStaticCollectObjectsLordWantsRivalCapturedIssue(object o, List<object> collectedObjects)
			{
				((LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060050F5 RID: 20725 RVA: 0x00170D2B File Offset: 0x0016EF2B
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetHero);
			}

			// Token: 0x060050F6 RID: 20726 RVA: 0x00170D40 File Offset: 0x0016EF40
			internal static object AutoGeneratedGetMemberValue_targetHero(object o)
			{
				return ((LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue)o)._targetHero;
			}

			// Token: 0x170010FF RID: 4351
			// (get) Token: 0x060050F7 RID: 20727 RVA: 0x00170D4D File Offset: 0x0016EF4D
			protected override int RewardGold
			{
				get
				{
					return 5000;
				}
			}

			// Token: 0x17001100 RID: 4352
			// (get) Token: 0x060050F8 RID: 20728 RVA: 0x00170D54 File Offset: 0x0016EF54
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=uc4M4bhG}Well, there is something I want. There is one {?TARGET_HERO.GENDER}lady{?}lord{\\?} of the {TARGET_FACTION} with whom I have a long, long relationship. And not a friendly one. Even though we are not now at war, as long as {?TARGET_HERO.GENDER}she{?}he{\\?} is free, I know my life and lands are not safe. As I say, it won't be easy at all. But whoever manages to do that, bring {?TARGET_HERO.GENDER}her{?}him{\\?} back alive to me, having my gratitude aside, will be a very rich man indeed.[if:convo_grave][ib:closed2]", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_FACTION", this._targetHero.Clan.Name);
					return textObject;
				}
			}

			// Token: 0x17001101 RID: 4353
			// (get) Token: 0x060050F9 RID: 20729 RVA: 0x00170DA4 File Offset: 0x0016EFA4
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=tzBybYcf}I am interested. Who is this {?TARGET_HERO.GENDER}woman{?}man{\\?}?", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001102 RID: 4354
			// (get) Token: 0x060050FA RID: 20730 RVA: 0x00170DD8 File Offset: 0x0016EFD8
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=zKhvUmeH}{?TARGET_HERO.GENDER}She{?}He{\\?} is {TARGET_HERO.NAME} from {TARGET_HERO.CLAN}. I want {?TARGET_HERO.GENDER}her{?}him{\\?} brought to me, so I can settle this score once and for all. I have {BASE_REWARD}{GOLD_ICON} that I have set aside. If you can bring me {TARGET_HERO.LINK} alive within a year, it is yours to claim.[if:convo_bared_teeth][ib:closed2]", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, true);
					textObject.SetTextVariable("BASE_REWARD", this.RewardGold);
					GameTexts.SetVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001103 RID: 4355
			// (get) Token: 0x060050FB RID: 20731 RVA: 0x00170E2C File Offset: 0x0016F02C
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=Ysjh2GF2}Hold on to that reward, then. I will bring {?TARGET_HERO.GENDER}her{?}him{\\?} alive.", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001104 RID: 4356
			// (get) Token: 0x060050FC RID: 20732 RVA: 0x00170E5E File Offset: 0x0016F05E
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001105 RID: 4357
			// (get) Token: 0x060050FD RID: 20733 RVA: 0x00170E61 File Offset: 0x0016F061
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001106 RID: 4358
			// (get) Token: 0x060050FE RID: 20734 RVA: 0x00170E64 File Offset: 0x0016F064
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=FoNfLOny}{ISSUE_OWNER.NAME} wants {TARGET_HERO.NAME} captured", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001107 RID: 4359
			// (get) Token: 0x060050FF RID: 20735 RVA: 0x00170EB0 File Offset: 0x0016F0B0
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=FoNfLOny}{ISSUE_OWNER.NAME} wants {TARGET_HERO.NAME} captured", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x06005100 RID: 20736 RVA: 0x00170EFA File Offset: 0x0016F0FA
			public LordWantsRivalCapturedIssue(Hero issueOwner, Hero targetHero) : base(issueOwner, CampaignTime.DaysFromNow(20f))
			{
				this._targetHero = targetHero;
			}

			// Token: 0x06005101 RID: 20737 RVA: 0x00170F14 File Offset: 0x0016F114
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.ClanInfluence)
				{
					return -0.3f;
				}
				return 0f;
			}

			// Token: 0x06005102 RID: 20738 RVA: 0x00170F29 File Offset: 0x0016F129
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.Rare;
			}

			// Token: 0x06005103 RID: 20739 RVA: 0x00170F2C File Offset: 0x0016F12C
			public override bool IssueStayAliveConditions()
			{
				return !this._targetHero.IsDead && !base.IssueOwner.IsDead && !this._targetHero.IsPrisoner && this._targetHero.PartyBelongedTo != null && base.IssueOwner.MapFaction != this._targetHero.MapFaction && base.IssueOwner.Clan != Clan.PlayerClan;
			}

			// Token: 0x06005104 RID: 20740 RVA: 0x00170F9C File Offset: 0x0016F19C
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flags, out Hero relationHero, out SkillObject skill)
			{
				relationHero = null;
				flags = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flags |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flags |= IssueBase.PreconditionFlags.AtWar;
				}
				if (Clan.PlayerClan.Tier < 2)
				{
					flags |= IssueBase.PreconditionFlags.ClanTier;
				}
				if (MobileParty.MainParty.MemberRoster.TotalHealthyCount < 50)
				{
					flags |= IssueBase.PreconditionFlags.NotEnoughTroops;
				}
				skill = null;
				return flags == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06005105 RID: 20741 RVA: 0x00171020 File Offset: 0x0016F220
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06005106 RID: 20742 RVA: 0x00171022 File Offset: 0x0016F222
			protected override void HourlyTick()
			{
			}

			// Token: 0x06005107 RID: 20743 RVA: 0x00171024 File Offset: 0x0016F224
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(300f), this.RewardGold, this._targetHero);
			}

			// Token: 0x06005108 RID: 20744 RVA: 0x00171048 File Offset: 0x0016F248
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x04001A99 RID: 6809
			private const int QuestTimeLimit = 300;

			// Token: 0x04001A9A RID: 6810
			[SaveableField(10)]
			private Hero _targetHero;
		}

		// Token: 0x02000654 RID: 1620
		public class LordWantsRivalCapturedIssueQuest : QuestBase
		{
			// Token: 0x06005109 RID: 20745 RVA: 0x0017104A File Offset: 0x0016F24A
			internal static void AutoGeneratedStaticCollectObjectsLordWantsRivalCapturedIssueQuest(object o, List<object> collectedObjects)
			{
				((LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x0600510A RID: 20746 RVA: 0x00171058 File Offset: 0x0016F258
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetHero);
			}

			// Token: 0x0600510B RID: 20747 RVA: 0x0017106D File Offset: 0x0016F26D
			internal static object AutoGeneratedGetMemberValue_targetHero(object o)
			{
				return ((LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssueQuest)o)._targetHero;
			}

			// Token: 0x0600510C RID: 20748 RVA: 0x0017107A File Offset: 0x0016F27A
			internal static object AutoGeneratedGetMemberValue_firstCounterOfferMade(object o)
			{
				return ((LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssueQuest)o)._firstCounterOfferMade;
			}

			// Token: 0x17001108 RID: 4360
			// (get) Token: 0x0600510D RID: 20749 RVA: 0x0017108C File Offset: 0x0016F28C
			private bool PlayerCapturedTargetHero
			{
				get
				{
					return (from x in MobileParty.MainParty.PrisonRoster.GetTroopRoster()
					where x.Character.IsHero
					select x).FirstOrDefault((TroopRosterElement x) => x.Character.HeroObject == this._targetHero).Character != null;
				}
			}

			// Token: 0x17001109 RID: 4361
			// (get) Token: 0x0600510E RID: 20750 RVA: 0x001710E8 File Offset: 0x0016F2E8
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=FoNfLOny}{ISSUE_OWNER.NAME} wants {TARGET_HERO.NAME} captured", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700110A RID: 4362
			// (get) Token: 0x0600510F RID: 20751 RVA: 0x00171132 File Offset: 0x0016F332
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x1700110B RID: 4363
			// (get) Token: 0x06005110 RID: 20752 RVA: 0x00171138 File Offset: 0x0016F338
			private TextObject _playerStartsQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=nB07bljx}{ISSUE_OWNER.LINK}, a {?ISSUE_OWNER.GENDER}lady{?}lord{\\?} of the {ISSUE_OWNER.CLAN}, has a personal vendetta against {TARGET_HERO.LINK} of the {TARGET_HERO.CLAN}. {?ISSUE_OWNER.GENDER}She{?}He{\\?} wants {TARGET_HERO.LINK} captured and brought back to {?ISSUE_OWNER.GENDER}her{?}him{\\?}. If you manage doing that, {?ISSUE_OWNER.GENDER}she{?}he{\\?} promised a reward of {REWARD_GOLD}{GOLD_ICON}. You agreed to find {TARGET_HERO.LINK} and bring {?TARGET_HERO.GENDER}her{?}him{\\?} to {ISSUE_OWNER.LINK} within one year.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, true);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, true);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x1700110C RID: 4364
			// (get) Token: 0x06005111 RID: 20753 RVA: 0x00171194 File Offset: 0x0016F394
			private TextObject _playerAcceptedOfferQuestFail
			{
				get
				{
					TextObject textObject = new TextObject("{=vh4bBfYq}You have accepted {TARGET_HERO.LINK}'s offer and freed {?TARGET_HERO.GENDER}her{?}him{\\?}. {?TARGET_HERO.GENDER}She{?}He{\\?} and {?TARGET_HERO.GENDER}her{?}his{\\?} clan would be very happy. On the other hand {ISSUE_OWNER.LINK} will feel {?ISSUE_OWNER.GENDER}she{?}he{\\?} is betrayed and be furious.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700110D RID: 4365
			// (get) Token: 0x06005112 RID: 20754 RVA: 0x001711E0 File Offset: 0x0016F3E0
			private TextObject _playerDeliveredPrisonerQuestSuccess
			{
				get
				{
					TextObject textObject = new TextObject("{=UIyhmGKC}You have handed over the prisoner {TARGET_HERO.LINK} to {ISSUE_OWNER.LINK}'s agent, who handed you {BASE_REWARD}{GOLD_ICON} denars as promised. He also says; {ISSUE_OWNER.LINK} is grateful for your service and sends {?ISSUE_OWNER.GENDER}her{?}his{\\?} regards.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("BASE_REWARD", this.RewardGold);
					GameTexts.SetVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x1700110E RID: 4366
			// (get) Token: 0x06005113 RID: 20755 RVA: 0x0017124C File Offset: 0x0016F44C
			private TextObject _playerCapturedTargetBrief1LogText
			{
				get
				{
					TextObject textObject = new TextObject("{=VdGyUQH0}You have captured {TARGET_HERO.LINK}. It looks like {?TARGET_HERO.GENDER}she{?}he{\\?} is desperate and very afraid of being sent to {ISSUE_OWNER.LINK} so for {?TARGET_HERO.GENDER}her{?}his{\\?} release, {?TARGET_HERO.GENDER}she{?}he{\\?} offers a sum of {BASE_REWARD_X_2}{GOLD_ICON} denars, double of what {ISSUE_OWNER.LINK} was willing to pay for his capture. {ISSUE_OWNER.LINK} on the other hand sends you a letter soon after {TARGET_HERO.LINK}'s capture. The letter reads:", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("BASE_REWARD_X_2", this.RewardGold * 2);
					GameTexts.SetVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x1700110F RID: 4367
			// (get) Token: 0x06005114 RID: 20756 RVA: 0x001712BC File Offset: 0x0016F4BC
			private TextObject _playerCapturedTargetBrief2LogText
			{
				get
				{
					TextObject textObject = new TextObject("{=vzF9atyv}My dear {PLAYER.NAME}, I have been informed that you have captured {TARGET_HERO.LINK}. This is great news. One of my agents will wait for you at the gates of the next settlement that belongs to my clan with the bounty I promised. You should deliver your prisoner to him as soon as you can. I have plans for {?TARGET_HERO.GENDER}her{?}him{\\?}. Thank you and best wishes, - {ISSUE_OWNER.LINK}", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001110 RID: 4368
			// (get) Token: 0x06005115 RID: 20757 RVA: 0x00171318 File Offset: 0x0016F518
			private TextObject _playerCapturedTargetBrief3LogText
			{
				get
				{
					TextObject textObject = new TextObject("{=1H6SKtUl}Deliver the prisoner to {ISSUE_OWNER.LINK} {?ISSUE_OWNER.GENDER}herself{?}himself{\\?} or one of {?ISSUE_OWNER.GENDER}her{?}his{\\?} settlements. If you don't want to deliver {TARGET_HERO.LINK}, talk with {?TARGET_HERO.GENDER}her{?}him{\\?} to negotiate on {?TARGET_HERO.GENDER}her{?}his{\\?} release.", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001111 RID: 4369
			// (get) Token: 0x06005116 RID: 20758 RVA: 0x00171364 File Offset: 0x0016F564
			private TextObject _targetKilledByPlayerLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=GlfwOWre}You have received a letter from {ISSUE_OWNER.LINK}; It reads: \"My dear {PLAYER.NAME}, I have been informed that that vile creature called {TARGET_HERO.LINK} has been slain by you! While this is great news, I had other plans for {?TARGET_HERO.GENDER}her{?}him{\\?}. What a pity. Anyway, I am feeling generous. So I will still pay half of what we had previously agreed upon. The messenger who brought you this note should give you the sum. Best wishes - {ISSUE_OWNER.LINK}\"", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001112 RID: 4370
			// (get) Token: 0x06005117 RID: 20759 RVA: 0x001713C0 File Offset: 0x0016F5C0
			private TextObject _questGiverCapturedTargetHero
			{
				get
				{
					TextObject textObject = new TextObject("{=2HIE7n9G}{ISSUE_OWNER.LINK} has captured {TARGET_HERO.LINK} {?ISSUE_OWNER.GENDER}herself{?}himself{\\?}, your contract with {ISSUE_OWNER.LINK} has canceled.", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001113 RID: 4371
			// (get) Token: 0x06005118 RID: 20760 RVA: 0x0017140C File Offset: 0x0016F60C
			private TextObject _targetHeroAndQuestGiverInSameFaction
			{
				get
				{
					TextObject textObject = new TextObject("{=4JE6bYIE}{ISSUE_OWNER.LINK} and {TARGET_HERO.LINK} are now part of the same faction so they can't fight against each other. Your contract with {ISSUE_OWNER.LINK} has canceled.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001114 RID: 4372
			// (get) Token: 0x06005119 RID: 20761 RVA: 0x00171456 File Offset: 0x0016F656
			private TextObject _warDeclaredQuestLog
			{
				get
				{
					TextObject textObject = new TextObject("{=cKz1cyuM}Your clan is now at war with {QUEST_GIVER_SETTLEMENT_FACTION}. Quest is canceled.", null);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT_FACTION", base.QuestGiver.MapFaction.Name);
					return textObject;
				}
			}

			// Token: 0x17001115 RID: 4373
			// (get) Token: 0x0600511A RID: 20762 RVA: 0x0017147F File Offset: 0x0016F67F
			private TextObject _timeOutLogText
			{
				get
				{
					return new TextObject("{=maXW8tps}You failed to capture and deliver the prisoner in time.", null);
				}
			}

			// Token: 0x0600511B RID: 20763 RVA: 0x0017148C File Offset: 0x0016F68C
			public LordWantsRivalCapturedIssueQuest(string questId, Hero giverHero, CampaignTime duration, int rewardGold, Hero targetHero) : base(questId, giverHero, duration, rewardGold)
			{
				this._targetHero = targetHero;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
				this._firstCounterOfferMade = false;
				this._questGiversAgentCharacterObject = null;
			}

			// Token: 0x0600511C RID: 20764 RVA: 0x001714BB File Offset: 0x0016F6BB
			private bool DialogCondition()
			{
				StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, null, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, null, false);
				return Hero.OneToOneConversationHero == base.QuestGiver;
			}

			// Token: 0x0600511D RID: 20765 RVA: 0x001714F4 File Offset: 0x0016F6F4
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=qaKh6vRl}Let's see if you are as good as your word. If you really manage, I admit, I will be very impressed. I look forward to meeting you again.[if:convo_mocking_aristocratic][ib:closed]", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.DialogCondition)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=xFHb9nAk}Have you been able to find {?TARGET_HERO.GENDER}her{?}his{\\?} whereabouts yet?", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.DialogCondition)).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += MapEventHelper.OnConversationEnd;
				}).BeginPlayerOptions().PlayerOption(new TextObject("{=ZkVP4RYV}Yes, I've captured {?TARGET_HERO.GENDER}her{?}him{\\?}.", null), null).Condition(() => this.PlayerCapturedTargetHero).NpcLine(new TextObject("{=qvlln5ej}Thanks, I knew I could trust you.[if:convo_happy][ib:confident2]", null), null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += this.PlayerDeliveredPrisonerQuestSuccess;
				}).CloseDialog().PlayerOption(new TextObject("{=fwQtClVo}I will deal with {?TARGET_HERO.GENDER}her{?}him{\\?} right away! ", null), null).NpcLine(new TextObject("{=fr4F4IQc}It's good to hear that, {PLAYER.NAME}.[if:convo_relaxed_happy][ib:hip] ", null), null, null).CloseDialog().PlayerOption(new TextObject("{=18NtjryL}Not yet, but I will soon.", null), null).NpcLine(new TextObject("{=zs8rZnf8}I will be waiting for your good news {PLAYER.NAME}.[if:convo_relaxed_happy][ib:hip]", null), null, null).CloseDialog().EndPlayerOptions();
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetTargetHeroDialogFlow(), this);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetTargetHeroCounterOffer1DialogFlow(), this);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetTargetHeroCounterOffer2DialogFlow(), this);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetQuestGiversAgentDialogFlow(), this);
			}

			// Token: 0x0600511E RID: 20766 RVA: 0x001716A4 File Offset: 0x0016F8A4
			private DialogFlow GetTargetHeroDialogFlow()
			{
				TextObject textObject = new TextObject("{=Mn4bI9Jg}What are you doing? Are you another one of {QUEST_GIVER.NAME}'s lackeys? Do you think you can hunt me like an animal.[if:convo_confused_normal][ib:closed]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
				TextObject textObject2 = new TextObject("{=qOhDHFyH}Are you another one of {QUEST_GIVER.NAME}'s lackeys? Did {?QUEST_GIVER.GENDER}she{?}he{\\?} send you to hunt me like an animal? Well, I think you've found you've caught not a hare but a lion.[if:convo_confused_annoyed][ib:aggressive]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject2, false);
				return DialogFlow.CreateDialogFlow("start", 125).BeginNpcOptions().NpcOption(textObject2, new ConversationSentence.OnConditionDelegate(this.target_hero_encounter_agressive_condition), null, null).NpcLine(new TextObject("{=TzvGs0v1}Well I guess it's too late to change your mind now, I decided to make an example of you.[if:convo_furious][ib:warrior]", null), null, null).CloseDialog().NpcOption(textObject, new ConversationSentence.OnConditionDelegate(this.target_hero_encounter_default_condition), null, null).BeginPlayerOptions().PlayerOption(new TextObject("{=WoAgHDrN}I'm bringing you in, one way or the other.", null), null).NpcLine(new TextObject("{=hzCTbbLP}You think you've caught a hare but instead you've caught a lion.[if:convo_furious][ib:warrior]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.player_target_hero_encounter_consequence)).CloseDialog().PlayerOption(new TextObject("{=pZm7HRDG}Don't worry I have no intention to attack.", null), null).NpcLine(new TextObject("{=eJuvk4om}Wise decision.[ib:closed][if:convo_bared_teeth]", null), null, null).Consequence(delegate
				{
					PlayerEncounter.LeaveEncounter = true;
				}).CloseDialog().EndPlayerOptions().EndNpcOptions();
			}

			// Token: 0x0600511F RID: 20767 RVA: 0x001717E0 File Offset: 0x0016F9E0
			private DialogFlow GetTargetHeroCounterOffer1DialogFlow()
			{
				TextObject textObject = new TextObject("{=dYa9oVSP}Fate is cruel. So, I am your prisoner. But you don't need to do {QUEST_GIVER.NAME}'s dirty work. For the sake of your honor, {?PLAYER.GENDER}lady{?}sir{\\?}, listen to me![if:convo_nervous2][ib:nervous]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				TextObject npcText = new TextObject("{=zliqo1Y8}{?PLAYER.GENDER}Madam{?}Sir{\\?}, I will pay double whatever {?QUEST_GIVER.GENDER}she{?}he{\\?} promised to release me. Believe me, you don't want a reputation as {?QUEST_GIVER.GENDER}her{?}his{\\?} kidnapper-for-hire.[if:convo_grave][ib:normal2]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				TextObject npcText2 = new TextObject("{=uBcBuDKV}It's no worse than taking {QUEST_GIVER.NAME}'s silver in the first place for this task. Do think it over.[if:convo_normal][ib:normal]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(textObject, null, null).Condition(new ConversationSentence.OnConditionDelegate(this.after_taken_prisoner_counter_offer_condition)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.FirstCounterOfferFinished)).BeginPlayerOptions().PlayerOption(new TextObject("{=SJfqzt8m}Go on... I'm listening", null), null).NpcLine(npcText, null, null).BeginPlayerOptions().PlayerOption(new TextObject("{=rFriAZcL}Can you really pay me {BASE_REWARD_X_2}{GOLD_ICON} for your freedom?", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.set_reward_x_2_and_gold_icon)).NpcLine(new TextObject("{=59ijHPtR}Yes. That is a lot but yes I can pay that.[if:convo_nonchalant][ib:confident]", null), null, null).BeginPlayerOptions().PlayerOption(new TextObject("{=E8wdxbui}All right, I accept. I release you now. Now pay me.", null), null).NpcLine(new TextObject("{=bWbcuOji}Yes. That is a lot but yes I can pay that. Thank you {?PLAYER.GENDER}milady{?}my Lord{\\?}. I knew we could reach an agreement.[if:convo_grateful][ib:confident]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestFailCounterOfferAccepted)).CloseDialog().PlayerOption(new TextObject("{=MacG8ikN}I will think about it.", null), null).NpcLine(new TextObject("{=UKTjwBxk}Please be quick about it!", null), null, null).CloseDialog().EndPlayerOptions().PlayerOption(new TextObject("{=czuvE3PC}Do you think I will break my word for a handful more silver?", null), null).NpcLine(npcText2, null, null).CloseDialog().EndPlayerOptions().PlayerOption(new TextObject("{=2v0eQ755}Sorry, not interested.", null), null).NpcLine(new TextObject("{=D1biQObM}I will pay double whatever {ISSUE_OWNER.NAME} is paying you! Please consider my offer![if:convo_nervous2][ib:nervous]", null), null, null).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x06005120 RID: 20768 RVA: 0x001719C8 File Offset: 0x0016FBC8
			private DialogFlow GetTargetHeroCounterOffer2DialogFlow()
			{
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(new TextObject("{=QDMbaUYv}My {?PLAYER.GENDER}lady{?}lord{\\?}! please tell me you have decided to release me.[if:convo_nervous]", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.counter_offer_2_condition)).BeginPlayerOptions().PlayerOption(new TextObject("{=tNo1Dctm}Yes. If you pay me {BASE_REWARD_X_2}{GOLD_ICON}, I will release you", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.set_reward_x_2_and_gold_icon)).NpcLine(new TextObject("{=jeljPTgV}Thank you, my {?PLAYER.GENDER}lady{?}lord{\\?}. I knew we could reach an agreement.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestFailCounterOfferAccepted)).PlayerOption(new TextObject("{=AOgrLJos}No. I haven't decided yet.", null), null).NpcLine(new TextObject("{=UKTjwBxk}Please be quick about it!", null), null, null).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x06005121 RID: 20769 RVA: 0x00171A7C File Offset: 0x0016FC7C
			private DialogFlow GetQuestGiversAgentDialogFlow()
			{
				return DialogFlow.CreateDialogFlow("start", 125).NpcLine(new TextObject("{=lYhWyuCM}Greetings {?PLAYER.GENDER}milady{?}sir{\\?}, {QUEST_GIVER.NAME} has sent me to collect {TARGET_HERO.NAME}.[if:convo_nonchalant][ib:demure2]", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.quest_givers_agent_dialog_condition)).NpcLine(new TextObject("{=1PCaW5YI}My liege {QUEST_GIVER.NAME} also instructed me to present you the sum of {REWARD_GOLD}{GOLD_ICON} denars for the prisoners exchange.", null), null, null).NpcLine(new TextObject("{=Mt1cSesD}My {?PLAYER.GENDER}lady{?}lord{\\?} also instructed me to express {?PLAYER.GENDER}her{?}his{\\?} gratitude for your services, and admiration for your skill.[if:convo_bemused][ib:demure]", null), null, null).BeginPlayerOptions().PlayerOption(new TextObject("{=itHCs6bB}I'm delivering {?TARGET_HERO.GENDER}her{?}him{\\?} as I promised.", null), null).NpcLine(new TextObject("{=RScf2bnd}Thank you {?PLAYER.GENDER}milady{?}sir{\\?}. My liege {?QUEST_GIVER.GENDER}lady{?}lord{\\?} {QUEST_GIVER.NAME} sends {?QUEST_GIVER.GENDER}her{?}his{\\?} regards. Here is the reward {?QUEST_GIVER.GENDER}she{?}he{\\?} has promised. I must take my leave now.[if:convo_bemused][ib:demure]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.PlayerDeliveredPrisonerQuestSuccess)).CloseDialog().PlayerOption(new TextObject("{=uHY7NqZf}I can't do this. I am releasing {TARGET_HERO.NAME}. Tell your master that {TARGET_HERO.NAME} is no longer a prisoner.", null), null).NpcLine(new TextObject("{=A8NttdZY}My {?QUEST_GIVER.GENDER}lady{?}lord{\\?} will be furious that you are going back on your word.[if:convo_annoyed][ib:closed2]", null), null, null).PlayerLine(new TextObject("{=UaSddsa2}My decision is final.", null), null).NpcLine(new TextObject("{=XrUPGyRO}You will regret your decision...[if:convo_grave][ib:closed]", null), null, null).CloseDialog().EndPlayerOptions().Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestFailCounterOfferAccepted));
			}

			// Token: 0x06005122 RID: 20770 RVA: 0x00171B7C File Offset: 0x0016FD7C
			private bool quest_givers_agent_dialog_condition()
			{
				StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, null, false);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, null, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, null, false);
				MBTextManager.SetTextVariable("REWARD_GOLD", this.RewardGold);
				GameTexts.SetVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				return CharacterObject.OneToOneConversationCharacter == this._questGiversAgentCharacterObject;
			}

			// Token: 0x06005123 RID: 20771 RVA: 0x00171BF7 File Offset: 0x0016FDF7
			private void FirstCounterOfferFinished()
			{
				this._firstCounterOfferMade = true;
				TakePrisonerAction.Apply(PartyBase.MainParty, this._targetHero);
			}

			// Token: 0x06005124 RID: 20772 RVA: 0x00171C10 File Offset: 0x0016FE10
			private bool common_first_dialogue_condition()
			{
				return Hero.OneToOneConversationHero == this._targetHero && this._targetHero.CurrentSettlement == null && !this.PlayerCapturedTargetHero && Campaign.Current.CurrentConversationContext != ConversationContext.CapturedLord;
			}

			// Token: 0x06005125 RID: 20773 RVA: 0x00171C46 File Offset: 0x0016FE46
			private void player_target_hero_encounter_consequence()
			{
				GameMenu.SwitchToMenu("encounter");
			}

			// Token: 0x06005126 RID: 20774 RVA: 0x00171C52 File Offset: 0x0016FE52
			private bool target_hero_encounter_agressive_condition()
			{
				return this.common_first_dialogue_condition() && this._targetHero.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction);
			}

			// Token: 0x06005127 RID: 20775 RVA: 0x00171C78 File Offset: 0x0016FE78
			private bool target_hero_encounter_default_condition()
			{
				return this.common_first_dialogue_condition() && !FactionManager.IsAlliedWithFaction(this._targetHero.MapFaction, Hero.MainHero.MapFaction);
			}

			// Token: 0x06005128 RID: 20776 RVA: 0x00171CA4 File Offset: 0x0016FEA4
			private bool after_taken_prisoner_counter_offer_condition()
			{
				if (Campaign.Current.CurrentConversationContext == ConversationContext.CapturedLord)
				{
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.QuestGiver.CharacterObject, null, false);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, null, false);
					return Hero.OneToOneConversationHero == this._targetHero && !this._firstCounterOfferMade;
				}
				return false;
			}

			// Token: 0x06005129 RID: 20777 RVA: 0x00171D02 File Offset: 0x0016FF02
			private bool counter_offer_2_condition()
			{
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, null, false);
				return Hero.OneToOneConversationHero == this._targetHero && this.PlayerCapturedTargetHero && this._firstCounterOfferMade;
			}

			// Token: 0x0600512A RID: 20778 RVA: 0x00171D33 File Offset: 0x0016FF33
			private bool set_reward_x_2_and_gold_icon()
			{
				MBTextManager.SetTextVariable("BASE_REWARD_X_2", this.RewardGold * 2);
				GameTexts.SetVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				return true;
			}

			// Token: 0x0600512B RID: 20779 RVA: 0x00171D58 File Offset: 0x0016FF58
			private void QuestFailCounterOfferAccepted()
			{
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold * 2, false);
				ChangeRelationAction.ApplyPlayerRelation(this._targetHero, 10, true, true);
				this.RelationshipChangeWithQuestGiver = -15;
				EndCaptivityAction.ApplyByReleasedByChoice(new FlattenedTroopRoster(1)
				{
					{
						this._targetHero.CharacterObject,
						false,
						0
					}
				});
				base.AddLog(this._playerAcceptedOfferQuestFail, false);
				base.CompleteQuestWithBetrayal(null);
			}

			// Token: 0x0600512C RID: 20780 RVA: 0x00171DC4 File Offset: 0x0016FFC4
			private void PlayerDeliveredPrisonerQuestSuccess()
			{
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				ChangeRelationAction.ApplyPlayerRelation(this._targetHero, -10, true, true);
				this.RelationshipChangeWithQuestGiver = 15;
				base.AddLog(this._playerDeliveredPrisonerQuestSuccess, false);
				base.CompleteQuestWithSuccess();
				if (Hero.OneToOneConversationHero == base.QuestGiver)
				{
					TransferPrisonerAction.Apply(this._targetHero.CharacterObject, PartyBase.MainParty, (base.QuestGiver.PartyBelongedTo != null) ? base.QuestGiver.PartyBelongedTo.Party : base.QuestGiver.CurrentSettlement.Party);
					return;
				}
				TransferPrisonerAction.Apply(this._targetHero.CharacterObject, PartyBase.MainParty, Settlement.CurrentSettlement.Party);
			}

			// Token: 0x0600512D RID: 20781 RVA: 0x00171E7F File Offset: 0x0017007F
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddLog(this._playerStartsQuestLogText, false);
			}

			// Token: 0x0600512E RID: 20782 RVA: 0x00171E95 File Offset: 0x00170095
			protected override void OnTimedOut()
			{
				this.RelationshipChangeWithQuestGiver = -5;
				base.AddLog(this._timeOutLogText, false);
			}

			// Token: 0x0600512F RID: 20783 RVA: 0x00171EAD File Offset: 0x001700AD
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06005130 RID: 20784 RVA: 0x00171EB5 File Offset: 0x001700B5
			protected override void HourlyTick()
			{
			}

			// Token: 0x06005131 RID: 20785 RVA: 0x00171EB8 File Offset: 0x001700B8
			protected override void RegisterEvents()
			{
				CampaignEvents.OnPlayerBattleEndEvent.AddNonSerializedListener(this, new Action<MapEvent>(this.OnPlayerBattleEventEnded));
				CampaignEvents.HeroPrisonerTaken.AddNonSerializedListener(this, new Action<PartyBase, Hero>(this.OnPrisonerTaken));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.HeroPrisonerReleased.AddNonSerializedListener(this, new Action<Hero, PartyBase, IFaction, EndCaptivityDetail>(this.OnHeroPrisonerReleased));
				CampaignEvents.SettlementEntered.AddNonSerializedListener(this, new Action<MobileParty, Settlement, Hero>(this.OnSettlementEntered));
				CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
			}

			// Token: 0x06005132 RID: 20786 RVA: 0x00171F7D File Offset: 0x0017017D
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06005133 RID: 20787 RVA: 0x00171F90 File Offset: 0x00170190
			private void OnHeroPrisonerReleased(Hero prisoner, PartyBase party, IFaction capturerFaction, EndCaptivityDetail detail)
			{
				if (base.IsOngoing && this.PlayerCapturedTargetHero && prisoner == this._targetHero)
				{
					TextObject textObject = new TextObject("{=VuwaQjUN}{TARGET_HERO.LINK} has managed to escape and {?TARGET_HERO.GENDER}she{?}he{\\?} is no longer a prisoner.", null);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					base.AddLog(textObject, false);
					this._firstCounterOfferMade = false;
				}
			}

			// Token: 0x06005134 RID: 20788 RVA: 0x00171FEA File Offset: 0x001701EA
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				this.CheckCancelConditions(DiplomacyHelper.IsWarCausedByPlayer(faction1, faction2, detail));
			}

			// Token: 0x06005135 RID: 20789 RVA: 0x00171FFA File Offset: 0x001701FA
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				this.CheckCancelConditions(false);
			}

			// Token: 0x06005136 RID: 20790 RVA: 0x00172003 File Offset: 0x00170203
			private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification = true)
			{
				if (victim == this._targetHero && killer == Hero.MainHero)
				{
					base.AddLog(this._targetKilledByPlayerLogText, false);
					GainRenownAction.Apply(Hero.MainHero, 10f, false);
					this.RelationshipChangeWithQuestGiver = 10;
					base.CompleteQuestWithSuccess();
				}
			}

			// Token: 0x06005137 RID: 20791 RVA: 0x00172044 File Offset: 0x00170244
			private void OnSettlementEntered(MobileParty party, Settlement settlement, Hero hero)
			{
				if (this.PlayerCapturedTargetHero && hero == Hero.MainHero && party == MobileParty.MainParty && settlement.IsFortification && settlement.OwnerClan == base.QuestGiver.Clan)
				{
					this._questGiversAgentCharacterObject = base.QuestGiver.Culture.Guard;
					CampaignMapConversation.OpenConversation(new ConversationCharacterData(CharacterObject.PlayerCharacter, PartyBase.MainParty, false, false, false, false, false, false), new ConversationCharacterData(this._questGiversAgentCharacterObject, null, false, false, false, false, false, false));
				}
			}

			// Token: 0x06005138 RID: 20792 RVA: 0x001720C8 File Offset: 0x001702C8
			private void OnPlayerBattleEventEnded(MapEvent mapEvent)
			{
				if ((mapEvent.IsPlayerMapEvent || mapEvent.IsPlayerSimulation) && mapEvent.PartiesOnSide(mapEvent.GetOtherSide(mapEvent.PlayerSide)).Any((MapEventParty x) => x.Party.Owner == this._targetHero) && mapEvent.HasWinner && mapEvent.WinningSide == mapEvent.PlayerSide && !this._targetHero.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					ChangeRelationAction.ApplyPlayerRelation(this._targetHero.MapFaction.Leader, -10, true, true);
					DeclareWarAction.ApplyByPlayerHostility(Hero.MainHero.MapFaction, this._targetHero.MapFaction);
				}
			}

			// Token: 0x06005139 RID: 20793 RVA: 0x00172174 File Offset: 0x00170374
			private void OnPrisonerTaken(PartyBase capturer, Hero prisoner)
			{
				if (prisoner == this._targetHero)
				{
					if (capturer == PartyBase.MainParty)
					{
						base.AddLog(this._playerCapturedTargetBrief1LogText, false);
						base.AddLog(this._playerCapturedTargetBrief2LogText, false);
						base.AddLog(this._playerCapturedTargetBrief3LogText, false);
						return;
					}
					if (base.QuestGiver.PartyBelongedTo != null && capturer == base.QuestGiver.PartyBelongedTo.Party)
					{
						if (base.IsOngoing)
						{
							base.AddLog(this._questGiverCapturedTargetHero, false);
							base.CompleteQuestWithCancel(null);
							return;
						}
					}
					else
					{
						TextObject textObject = TextObject.Empty;
						if (capturer.IsMobile)
						{
							textObject = new TextObject("{=gq8sgb2J}{TARGET_HERO.LINK} has been taken prisoner by {OTHER_HERO.LINK}.", null);
							StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
							StringHelpers.SetCharacterProperties("OTHER_HERO", ConversationHelper.GetConversationCharacterPartyLeader(capturer), textObject, false);
						}
						else if (capturer.IsSettlement)
						{
							textObject = new TextObject("{=HkvlHhPN}{TARGET_HERO.LINK} has been taken prisoner and thrown into the dungeons of {SETTLEMENT}.", null);
							StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
							textObject.SetTextVariable("SETTLEMENT", capturer.Settlement.EncyclopediaLinkWithName);
						}
						if (textObject != TextObject.Empty)
						{
							base.AddLog(textObject, false);
						}
					}
				}
			}

			// Token: 0x0600513A RID: 20794 RVA: 0x0017229C File Offset: 0x0017049C
			private void CheckCancelConditions(bool causedByPlayer = false)
			{
				if (base.IsOngoing)
				{
					if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
					{
						if (causedByPlayer)
						{
							base.CompleteQuestWithFail(null);
						}
						else
						{
							base.CompleteQuestWithCancel(null);
						}
						base.AddLog(this._warDeclaredQuestLog, false);
						return;
					}
					if (base.QuestGiver.MapFaction == this._targetHero.MapFaction)
					{
						base.CompleteQuestWithCancel(null);
						base.AddLog(this._targetHeroAndQuestGiverInSameFaction, false);
					}
				}
			}

			// Token: 0x04001A9B RID: 6811
			[SaveableField(1)]
			private Hero _targetHero;

			// Token: 0x04001A9C RID: 6812
			[SaveableField(2)]
			private bool _firstCounterOfferMade;

			// Token: 0x04001A9D RID: 6813
			private CharacterObject _questGiversAgentCharacterObject;
		}

		// Token: 0x02000655 RID: 1621
		public class LordWantsRivalCapturedIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x0600513F RID: 20799 RVA: 0x0017236B File Offset: 0x0017056B
			public LordWantsRivalCapturedIssueTypeDefiner() : base(51400)
			{
			}

			// Token: 0x06005140 RID: 20800 RVA: 0x00172378 File Offset: 0x00170578
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssue), 1, null);
				base.AddClassDefinition(typeof(LordWantsRivalCapturedIssueBehavior.LordWantsRivalCapturedIssueQuest), 2, null);
			}
		}
	}
}
